home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------- */
- /* Functions to access ini file */
- /* By MaVaTi, for ClipWatch */
- /* ---------------------------- */
-
- int ReadStringParamIni(char * Search,char * Def,char * Res,char * IniFile)
- {
- FILE * File;
- char Line[255];
- char * NotFin;
- int Fnd=FALSE;
- File=fopen(IniFile,"rt");
- if (File)
- {
- do
- {
- NotFin=fgets(Line,255,File);
- if (strncmp(Search,Line,strlen(Search))==0)
- {
- if (Line[strlen(Search)]=='=')
- {
- Fnd=TRUE;
- strcpy(Res,&Line[strlen(Search)+1]);
- Res[strlen(Res)-1]='\0';
- }
- }
- }
- while (NotFin&&(!Fnd));
- fclose(File);
- }
- if (!Fnd)
- strcpy(Res,Def);
- return Fnd;
- }
-
- long ReadIntParamIni(char * Search,long Def,char * IniFile)
- {
- char tmp[50];
- if (ReadStringParamIni(Search,"",tmp,IniFile))
- return atol(tmp);
- else
- return Def;
- }
-
-
- int WriteStringParamIni(char * Search,char * NewVal,char * IniFile)
- {
- FILE * OldFile;
- FILE * NewFile;
- char OldIniFile[255];
- char Line[255];
- char * NotFin;
- int Fnd=FALSE;
- strcpy(OldIniFile,IniFile);
- strcat(OldIniFile,".bak");
- rename(IniFile,OldIniFile);
- NewFile=fopen(IniFile,"wt");
- if (NewFile)
- {
-
- OldFile=fopen(OldIniFile,"rt");
- if (OldFile)
- {
- do
- {
- NotFin=fgets(Line,255,OldFile);
- if (strncmp(Search,Line,strlen(Search))==0)
- {
- if (Line[strlen(Search)]=='=')
- {
- Fnd=TRUE;
- strcpy(&Line[strlen(Search)+1],NewVal);
- strcat(Line,"\n");
- }
- }
- if(NotFin)
- {
- fputs(Line,NewFile);
- }
- }
- while (NotFin);
- fclose(OldFile);
-
- }
-
- if (!Fnd)
- {
- strcpy(Line,Search);
- strcat(Line,"=");
- strcat(Line,NewVal);
- strcat(Line,"\n");
- fputs(Line,NewFile);
- }
-
- fclose(NewFile);
- }
- remove(OldIniFile);
- return Fnd;
- }
-
- long WriteIntParamIni(char * Search,long NewVal,char * IniFile)
- {
- char tmp[50];
- int Fnd;
- sprintf(tmp,"%u",NewVal);
- Fnd=WriteStringParamIni(Search,tmp,IniFile);
- return Fnd;
- }
-